package com.agencia.socketserver;

import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.ServletConfig;

public class errors {
	private static errors INSTANCE = null;
	private static ServletConfig servletConfig = null;
	
	private errors(){}
	
	private synchronized static void createInstance(){
		if(INSTANCE == null){
			INSTANCE = new errors();
		}
	}
	
	public static errors getInstance(){
		createInstance();
		return INSTANCE;
	}
	
	
	
	public void writeError(String error)  {
		Date fecha = new Date();
		SimpleDateFormat dateLog = new SimpleDateFormat("yyyyMMdd-HH:mm:ss");		
		try {
			servletConfig.getServletContext().log(dateLog.format(fecha)+"          "+ error);
		} catch (Exception e) {
			// TODO: handle exception
			System.out.println(e.getMessage());
		}
	}

	public static ServletConfig getServletConfig() {
		return servletConfig;
	}

	public static void setServletConfig(ServletConfig servletConfig) {
		errors.servletConfig = servletConfig;
	}
}
